package com.dashu.core.controller;

import com.dashu.core.result.PageEnty;
import com.dashu.core.result.ResultBean;
import com.dashu.core.dto.OperatorDTO;
import com.dashu.core.service.OperatorService;
import com.dashu.core.vo.OperatorVO;
import com.dashu.core.vo.UpdateEntityVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Author xys
 * @Date 2020/11/17 15:21
 */

@RequestMapping("dashu/operator")
@RestController
@Slf4j
@Api(value = "dashu/operator", tags = {"运营商模块"}, description = "后台")
public class OperatorController {

    @Autowired
    private OperatorService operatorService;
//    @Autowired
//    RestTemplate restTemplate;

    @PostMapping("/addOperator")
    @ApiOperation(value = "运营商添加", notes = "运营商添加")
    public ResultBean<OperatorDTO> addOperator(@RequestBody @Validated OperatorVO operatorVO) {
        return new ResultBean<>(1, "运营商添加", operatorService.add(operatorVO));
    }

    @PostMapping("/updataOperator")
    @ApiOperation(value = " 运营商信息修改", notes = "运营商信息修改")
    public ResultBean<OperatorDTO> updataOperator(@RequestBody @Validated UpdateEntityVO<OperatorVO> updateEntityVO) {
        return new ResultBean<>(1, "运营商信息修改", operatorService.updataByOperatorId(updateEntityVO));

    }

    @GetMapping("/findBase")
    @ApiOperation(value = "父节点查询运营列表", notes = "父节点查询运营列表")
    public ResultBean<List<OperatorDTO>> findBase(@RequestBody @Validated PageEnty<Long> creteUserVo) {
        return new ResultBean<>(1, "父节点查询运营列表", operatorService.findByCreteUser(creteUserVo));

    }
    @GetMapping("/findOperator")
    @ApiOperation(value = "运营信息查询", notes = "运营信息查询")
    public ResultBean<OperatorDTO> findOperator(@RequestBody @Validated long operatorId) {
        return new ResultBean<>(1, "运营信息查询", operatorService.findByOperatorId(operatorId));

    }
    @DeleteMapping("/deleteOperator")
    @ApiOperation(value = "运营商信息删除", notes = "运营商信息删除")
    public ResultBean<Boolean> deleteOperator(@RequestBody @Validated long operatorId) {
        return new ResultBean<>(1, "运营商信息删除", operatorService.deleteByOperatorId(operatorId));

    }

}
